<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./OL_SDK/include-openlayers-local.js"></script>
    <script src="./libs/gaode.js"></script>
</head>

<body>
    <button onclick="addLine()">添加线</button>
    <div id="map">
    </div>
    <script>
        var docLayer = new Zondy.Map.Doc("", "zxd-plus-pla", {

        })
        /* [114,30] [120,30] */
        var map = new ol.Map({
            target: "map",
            layers: [gaode, docLayer],
            view: new ol.View({
                projection: 'EPSG:4326',
                center: [114.30, 30.50],
                zoom: 4
            })
        })
        function addLine() {

            /* 1、创建要素 geometry+style+attr */
            /* 2、创建要素集添加要素 */
            /* 3、调用服务添加要素集 */
            // geometry
            var pointObj = new Array();
            pointObj[0] = new Zondy.Object.Point2D(114, 30);
            pointObj[1] = new Zondy.Object.Point2D(120, 30);
            pointObj[1] = new Zondy.Object.Point2D(130, 30);
            var gArc = new Zondy.Object.Arc(pointObj);
            //构成线的折线
            var gAnyLine = new Zondy.Object.AnyLine([gArc]);
            //设置线要素的几何信息
            var gline = new Zondy.Object.GLine(gAnyLine);
            //设置要素的几何信息
            var fGeom = new Zondy.Object.FeatureGeometry({ LinGeom: [gline] });
            /* style */
            //设置添加线要素的图形参数信息
            var clineInfo = new Zondy.Object.CLineInfo({
                "Color": 1,
                "LinStyleID": 0,
                "LinStyleID2": 17,
                /* 线宽不能太大,不然会被盖住 */
                "LinWidth": 0.05,
                "Xscale": 10,
                "Yscale": 10
            });
            //设置要素的图形参数信息
            var graphicInfo = new Zondy.Object.WebGraphicsInfo({
                InfoType: 2,
                LinInfo: clineInfo
            });
            /* 属性 */
            var attValue = [];

            //创建一个线要素
            var newFeature = new Zondy.Object.Feature({
                fGeom: fGeom,
                GraphicInfo: graphicInfo,
                AttValue: attValue
            });
            //设置要素为线要素
            newFeature.setFType(2);
            /* 2、要素集  映射 -- 要素的添加 */
            var featureSet = new Zondy.Object.FeatureSet();
            var fldNumber = 0; //属性个数
            var fldName = [];
            var fldType = [];
            //创建属性结构设置对象
            var cAttStruct = new Zondy.Object.CAttStruct({ FldName: fldName, FldNumber: fldNumber, FldType: fldType });
            //设置要素数据集的树形结构
            featureSet.AttStruct = cAttStruct;
            //将添加的线要素添加到属性数据集中
            featureSet.addFeature(newFeature);
            /* 3、调用服务添加要素集 */
            //创建一个地图编辑对象
            var editDocFeature = new Zondy.Service.EditDocFeature("zxd-plus-pla", 1, {

            });
            editDocFeature.add(featureSet, onLineSuccess);
        }

        function onLineSuccess(data) {
            if (data.succeed) {
                alert("添加点要素成功！");
                docLayer.refresh();
            } else {
                alert("添加点要素失败！");
            }
        }
    </script>
</body>

</html>